import time
import unittest

import ddt
from BeautifulReport import BeautifulReport

from selenium import webdriver

from page.addspct1Page import addspct1Page
from page.addspct2Page import addspct2Page
from page.alertPage import alertPage
from page.commentsPage import commentsPage
from page.loginPage import loginPage
from page.registerPage import registerPage
from driver.readCsv import getregisterdata, getlogindata, getsearch1data1, getaddspct1data1, getcommentsdata
from page.search1Page import search1Page


@ddt.ddt
class TestCase(unittest.TestCase):

    # driver = webdriver.Chrome()

    def setUp(self):
        self.driver = webdriver.Chrome()
        # self.alertPage = alertPage(self.driver)
        # self.registerPage = registerPage(self.driver)
        # self.loginPage = loginPage(self.driver)
        # self.search1Page = search1Page(self.driver)
        # self.addspct1Page = addspct1Page(self.driver)
        self.commentsPage = commentsPage(self.driver)

    # @ddt.unpack
    # @ddt.data(*getregisterdata())
    # def testVipRegister(self,username,email,password,enpassword,msn,qq,bgnum,jtnum,phonenum,pwddn,succeed,failed):
    #     try:
    #         self.registerPage.vip_register(username,email,password,enpassword,msn,qq,bgnum,jtnum,phonenum,pwddn)
    #         time.sleep(2)
    #
    #         # msg = self.registerPage.find_Element(self.registerPage.msg_context).get_attribute("textContent")
    #         self.driver.switch_to.frame(0)
    #         msg2 = self.registerPage.find_Element(self.registerPage.msg_context2).get_attribute("textContent")
    #         #print("msg = \n" + msg)
    #         print("msg2 = \n" , msg2)
    #         #self.assertEqual(msg,succeed)
    #         print(succeed)
    #     except:
    #         print(failed)
    #
    # @ddt.unpack
    # @ddt.data(*getlogindata())
    # def testVipLogin(self,username,password,succeed,failed):
    #     try:
    #         self.loginPage.vip_login(username,password)
    #         msg = self.loginPage.find_Element(self.loginPage.msg_context).get_attribute("textContent")
    #
    #         self.assertEqual(msg,succeed)
    #         time.sleep(1)
    #         print(msg)
    #     except:
    #         print(failed)
    #
    # @ddt.unpack
    # @ddt.data(*getsearch1data1())
    # def testFunSearch1(self,goods,succeed,failed):
    #     try:
    #         self.search1Page.fun_search1(goods)
    #         msg1 = self.search1Page.find_Element(self.search1Page.msg_context1).get_attribute("textContent")
    #         self.assertEqual(msg1,succeed)
    #         print("搜索成功！")
    #     except:
    #         print(failed)

    # @ddt.unpack
    # @ddt.data(*getaddspct1data1())
    # def testFunAddSpct1(self,username,password,count,succeed,failed):
    #     try:
    #         self.addspct1Page.fun_addspct1(username,password,count)
    #         print(succeed)
    #     except:
    #         print(failed)

    @ddt.unpack
    @ddt.data(*getcommentsdata())
    def testCommenting(self,username,password,text,succeed,failed):
        try:
            self.commentsPage.commenting(username,password,text)
            print(succeed)
        except:
            print(failed)


    def tearDown(self):
        self.driver.quit()

def suite(self):
        # 创建一个测试套件
        suite = unittest.TestSuite()
        # 将测试用例加载到测试套件中
        loader = unittest.TestLoader()  # 创建一个用例加载对象
        suite.addTest(loader.loadTestsFromTestCase(TestCase))
        return suite

if __name__ == '__main__':
    br = BeautifulReport(suite())
    br.report(filename='testdemoreport.html', description='测试报告', log_path='.', report_dir='D:/PycharmProjects/ecShop/autoTest/report')








